package handler;

import java.net.Socket;
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: rainman
 * Date: 2009-6-2
 * Time: 15:09:18
 * To change this template use File | Settings | File Templates.
 */
public class DefaultHandler implements Handler {
    public void doHandle(Socket socket, int connectorNo) throws IOException {
        boolean exit = false;
        
        InputStream is = socket.getInputStream();
        OutputStream os = socket.getOutputStream();

        Scanner in = new Scanner(is);
        PrintWriter out = new PrintWriter(os);

        while (in.hasNextLine() && !exit) {
            String nextLine = in.nextLine();
            System.out.println("get words like this : " + nextLine);
            if ("bye".equalsIgnoreCase(nextLine.trim())) {
                System.out.print("exiting the connection...");
                exit = true;
                break;
            }
        }
        System.out.print("done!\n");
    }
}
